<template>
  <div class="home">
    <!--<el-dialog title="批量添加省份" :visible.sync="update_Superior">-->
      <el-form>
        <el-form-item label="设置省份" :label-width="formLabelWidth">
          <el-select v-model="ShengFen" placeholder="请选择">
            <el-option
              v-for="item in prosheng"
              :key="item.name"
              :label="item.name"
              :value="item.name">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="选择操作群体" :label-width="formLabelWidth">
          <el-button type="primary" @click="userclass(2)">业务员</el-button>
          <el-button type="success" @click="userclass(3)">一级代理</el-button>
          <el-button type="success" @click="userclass(4)">二级代理</el-button>
          <!--<el-button type="info" @click="userclass(5)">用户</el-button>-->
        </el-form-item>
        <el-form-item label="选择用户" :label-width="formLabelWidth">
          <el-transfer
            filterable
            :filter-method="filterMethod"
            filter-placeholder="请输入电话号码"
            v-model="valueusers"
            :titles="titlesa"
            :props="{
                 key: 'id',
                 label: 'nickname'
                 }"
            :data="data2">
          </el-transfer>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="update_Superior = false">取 消</el-button>
        <el-button type="primary" @click="updateSuperior">确 定</el-button>
      </div>
    <!--</el-dialog>-->
  </div>
</template>
<script>
  import prosheng from 'sc/Province'
  export default {
    components: {},
    data(){
      return {
        prosheng: prosheng.proa,  //全国省份
        ShengFen: '',//选择省份的值
        data2: [],//方法
        valueusers: [],   //
        filterMethod(query, item) {
          return item.phone.toString().indexOf(query) > -1;
        },
        formLabelWidth: '120px',
        ShengFenvalue1: '',
        titlesa: ['搜索用户', '选中用户'],
        salesman: '',//业务员
        update_Superior: true, //批量修改省份状态
      }
    },
    methods: {
      userclass(e){ //
        this.userphoneSuperior(e);
      },
      updateSuperior(){ //批量设置省份
        if(this.ShengFen == ''){
          this.$notify.error({
            title: '错误',
            message: '省份未选择'
          });
            return false;
        }
        if(this.valueusers == ''){
          this.$notify.error({
            title: '错误',
            message: '用户未选择'
          });
          return false;
        }

        this.http.post({
          'api': 'setprovince',
          'data': {
            'data': {
              "province": this.ShengFen,
              'userids': this.valueusers,
            }
          },
        }).then((res) => {
            console.log(res.data);

          this.update_Superior = false;
            if(res.data.data.old){
              this.$notify({
                title: '设置成功',
                message: '替换了--' + res.data.data.old.nickname+'--请记得修改',
                type: 'success'
              });
            }else{
              this.$h.dataSuccess(res.data, this);
            }



        }, (err) => {
          if (err) {
            this.$h.Ed(err, this);
          }
        })

      },
      userphoneSuperior(type){  //未选择的省份用户
        this.http.post({
          'api': 'searchuser',
          'data': {
            'data': {
              "value": null,
              'search': 'province',
              'type': type,
            }
          },
        }).then((res) => {
          this.data2 = res.data;
        }, (err) => {
          if (err) {
            this.$h.Ed(err, this);
          }
        })
      },
    },
    watch: {},
    computed: {
      //计算属性
    },
    mounted(){
      //生命周期
    }
  }
</script>
<style scoped>
  .home {
    width: 100%;
    height: 100%;
  }
</style>
